<template>
	<Modal v-model="modal" :title="modalTitle">
		<Form ref="formValidate" :model="editData" :label-width="100">
			<FormItem label="上传退款凭证:">

			</FormItem>
			<FormItem label="租赁费用:">
				<upload-img @success='imgUploadSuccess'>
					<Button icon='ios-cloud-upload-outline'>点击上传图片</Button>
				</upload-img>
				<img class="uploadSuccess" :src="editData.sellerProof" alt="">
			</FormItem>
			<FormItem label="应退金额:">
				<upload-img @success='imgUploadMoneySuccess'>
					<Button icon='ios-cloud-upload-outline'>点击上传图片</Button>
				</upload-img>
				<img class="uploadSuccess" :src="editData.buyersProof" alt="">
			</FormItem>
			<FormItem label="备注:">
				<Input v-model="editData.platformNote" type="textarea" />
			</FormItem>
		</Form>
		<div slot="footer">


			<Button type="primary" @click="submit" :loading="loadingBtn">
				<span v-if="!loadingBtn">确定</span>
				<span v-else>请稍候...</span>
			</Button>
			<Button @click="cancel">取消</Button>
		</div>
	</Modal>
</template>

<script>
	import uploadImg from '../../components/upload'
	export default {
		components: {
			uploadImg
		},
		props: {
			type: String
		},
		data() {
			return {
				modal: false,
				modalTitle: '',
				editData: {
					sellerProof: '',
					buyersProof: '',
					platformNote: '',
					returnType: 0
				},
				returnId: 0,
				isEdit: false,
				loadingBtn: false
			}
		},
		methods: {

			show(res) {
				this.$nextTick(() => {
					this.modal = true
					this.returnId = res.returnId
					switch (this.type) {
						case 'add':
							this.isEdit = false
							this.modalTitle = '退款'
							break
						case 'edit':
							this.isEdit = true
							this.modalTitle = '修改'
							this.$http.post('/parts/return/queryid', {
								id: res.returnId
							}).then(res => {
								if (res.status == 200) {
									if (res.data.code == 200) {
										this.editData = {
											sellerProof: res.data.data.sellerProof,
											buyersProof: res.data.data.buyersProof,
											platformNote: res.data.data.platformNote,
											returnId: res.data.data.returnId
										}

									}

								}

							})
							this.modalTitle = '编辑'
							break
					}
				})

			},

			//取消
			cancel() {
				this.modal = false;
			},
			//上传成功
			imgUploadSuccess(res) {
				this.editData.sellerProof = res.res.filePath;
			},
			imgUploadMoneySuccess(res) {
				this.editData.buyersProof = res.res.filePath;
			},
			//提交
			submit() {
				let data = {
					sellerProof: this.editData.sellerProof,
					buyersProof: this.editData.buyersProof,
					platformNote: this.editData.platformNote,
					returnId: this.returnId,
					returnType: 5
				}
				this.$http.post('/parts/return/save', data).then(res => {
					if (res.status == 200) {
						if (res.data.code == 200) {
							this.$Message.success('操作成功')
							this.modal = false
							setTimeout(function() {
								window.reload();
							}, 4000)
							
							this.$emit('table')
						}

					}
				})

			},
			modalChange(state) {
				if (state) {

				} else {
					this.$refs.formValidate.resetFields()
				}
			}
		}
	}
</script>
<style scoped>
	.uploadSuccess {
		width: 200px;
		height: 100px;
	}
</style>
